﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common.Localization;

namespace UI
{
    public partial class ExtendedCell : UserControl, ILocalizable
    {
        private string value;

        private Cell cell;

        public ExtendedCell()
        {
            this.InitializeComponent();
        }

        public ExtendedCell(Cell cell)
        {
            this.InitializeComponent();

            this.Cell = cell;
        }

        public event EventHandler Close;

        public Cell Cell
        {
            get
            {
                return this.cell;
            }

            set
            {
                this.cell = value;
                this.Color = this.cell.Color;
                this.Value = this.cell.Value;
                //this.Invalidate();
            }

        }

        public Color Color
        {
            get
            {
                return this.colorPanel.BackColor;
            }

            set
            {
                this.colorPanel.BackColor = value;
                this.colorPanel.Invalidate();
            }
        }

        public string Value
        {
            get
            {
                return this.value;
            }

            set
            {
                this.value = value;
                this.valueLabel.Text = value;
                this.valueLabel.Left = this.tabControl.Left - this.valueLabel.Width - 5;
            }
        }

        public void Localize()
        {
            this.closeLinkLabel.Text = LocalizationProvider.GetMessage("close");
        }

        private void CloseLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (this.Close != null)
            {
                this.Close(this.Cell, null);
            }
        }
    }
}